package com.le.tester.book.concurrentjavafight.l8_1_1;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * createTime：2022/11/23 9:58
 * description：线程死锁
 */
public class ThreadDeadLock {

    public ExecutorService exec = Executors.newSingleThreadExecutor();

    public class RenderPageTask implements Callable<String> {


        @Override
        public String call() throws Exception {

            Future<String> header, footer;
            //该任务中，套用了另一个任务

            header = exec.submit(new LoadFileTask("header.html"));
            footer = exec.submit(new LoadFileTask("footer.html"));

            String page = renderBody();
            //任务里面嵌套了其他的任务，在等待其他任务返回结果，但是一直在等待，锁无法释放，那么将发生死锁
            return header.get() + page + footer.get();
        }

        private String renderBody() {
            return "page";
        }
    }
}
